# frozen_string_literal: true

module Types
  module VulnerabilityDetails
    # rubocop: disable Graphql/AuthorizeTypes
    # The object rendered here is a hash, not a rich type we can authorize.
    # The authorization happens on the security report type
    # (Types::PipelineSecurityReportFindingType, Types::VulnerabilityType, ...)
    class NamedListType < BaseType
      graphql_name 'VulnerabilityDetailNamedList'
      description 'Represents the vulnerability details named list'

      field :items, [NamedListItemType],
        alpha: { milestone: '16.1' },
        null: false, description: 'Named list of details.'

      def items
        object.fetch(:items, []).map do |field_name, field|
          {
            name: field["name"],
            field_name: field_name,
            description: field["description"],
            value: field
          }
        end
      end
    end
    # rubocop: enable Graphql/AuthorizeTypes
  end
end
